package com.hiwan.unions.adapter.fragmentAdapters;

import android.content.Context;
import android.content.SharedPreferences;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hiwan.unions.R;
import com.hiwan.unions.adapter.bean.CouponBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by llg on 2016/3/19.
 */
public class CouponAdapter extends BaseAdapter {
    private List<CouponBean> cDates = new ArrayList<CouponBean>();
    private Context mContext;
    protected SharedPreferences userInfo;

    public CouponAdapter(Context contex, List<CouponBean> cDates) {
        this.mContext = contex;
        this.cDates = cDates;
    }

    @Override
    public int getCount() {
        return cDates.size();
    }

    @Override
    public Object getItem(int position) {
        return cDates.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.item_event_my, null);
            holder.layout_no = (LinearLayout) convertView.findViewById(R.id.layout_no);
            holder.layout_yes = (LinearLayout) convertView.findViewById(R.id.layout_yes);
            holder.title_2 = (TextView) convertView.findViewById(R.id.title_2);
            holder.content_2 = (TextView) convertView.findViewById(R.id.content_2);
            holder.title = (TextView) convertView.findViewById(R.id.title);
            holder.content = (TextView) convertView.findViewById(R.id.content);
            holder.date = (TextView) convertView.findViewById(R.id.date);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        setData(holder, position);
        return convertView;
    }

    /**
     * 设置viewHolder的数据  1型
     *
     * @param holder
     * @param itemIndex
     */
    private void setData(ViewHolder holder, int itemIndex) {
        holder.title.setText(cDates.get(itemIndex).getTitle());
        holder.content.setText(cDates.get(itemIndex).getImage());
        holder.title_2.setText(cDates.get(itemIndex).getTitle());
        holder.content_2.setText(cDates.get(itemIndex).getImage());

    }

    private class ViewHolder {
        private LinearLayout layout_yes;
        private LinearLayout layout_no;
        private TextView title_2;
        private TextView content_2;
        private TextView title;
        private TextView content;
        private TextView date;
    }
}